;(function () {
  var timer = null
  var PAGE_WIDTH = 750 // 设计稿的宽度
  var PAGE_FONT_SIZE = 100 // 设计稿1rem的大小

  function onResize () {
    var e = (PAGE_FONT_SIZE * document.documentElement.clientWidth) / PAGE_WIDTH
    document.documentElement.style.fontSize = e + 'px'
    // 二次计算缩放像素，解决移动端webkit字体缩放bug
    var realitySize = parseFloat(
      window.getComputedStyle(document.documentElement).fontSize
    )
    if (e !== realitySize) {
      e = (e * e) / realitySize
      document.documentElement.style.fontSize = e + 'px'
    }
  }
  window.addEventListener('resize', function () {
    if (timer) clearTimeout(timer)
    timer = setTimeout(onResize, 100)
  })
  onResize()
})()
